<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\App;

class AddressResource extends JsonResource
{
  protected $formats;

  public function toArray($request)
  {
    $this->formats = config('coreapi.' . App::getLocale());

    return [
      'id' => $this->id,
      'address' => $this->address,
      'house_number' => $this->house_number,
      'hamlet' => $this->hamlet,
      'active' => $this->active,
      'created_at' => localizedFormat($this->created_at, 'datetime'),
      'updated_at' => localizedFormat($this->updated_at, 'datetime'),
      'user' => new UserResource($this->whenLoaded('user')),
      'district' => new DistrictResource($this->whenLoaded('district')),
      'city' => new CityResource($this->whenLoaded('city')),
      'zipcode' => new ZipcodeResource($this->whenLoaded('zipcode')),
      'type' => new TypeResource($this->whenLoaded('type')),
    ];
  }
}
